<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>检测点管理</title>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="bootstrap/js/bootstrap.js" type="text/javascript"></script>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.css">
    <script src="layui/layui.js"></script>
    <link rel="stylesheet" href="layui/css/layui.css">
    <style>
        body{
            margin-top: 0;
            padding: 30px;
        }
    </style>
</head>
<body>
<ol class="breadcrumb">
    <li><a href="/mainbg">主页</a></li>
    <li><a href="#">检测点管理</a></li>
</ol>
<div id="pointInfo" class="container-fluid">
    <button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal" onclick="findAllProvince()">
        添加检测点
    </button>
    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">添加检测点</h4>
                </div>
                <form id="addForm">
                    <div class="modal-body">
                        <div class="form-group form-inline">
                            <label for="name">医院名称</label>
                            <input type="text" name="name" class="form-control" id="name" placeholder="请输入医院名称">
                        </div>
                        <div class="form-group form-inline">
                            <label for="quiz1" style="width: 56px;">地区</label>
                            <select id="quiz1" style="width: 139px;" name="provinceid" lay-verify="required" class="form-control">
                                <option value="">请选择省</option>
                            </select>
                            <select id="quiz2" style="width: 139px;" name="cityid" lay-verify="required" class="form-control">
                                <option value="">请选择市</option>
                                <span th:each="citys:${cityList}">
                                    <option th:value="${citys.cityid}" th:text="${citys.city}"></option>
                                </span>
                            </select>
                            <select id="quiz3" style="width: 139px;" name="areaid" lay-verify="required" class="form-control">
                                <option value="">请选择县/区</option>
                                <span th:each="areas:${areaList}">
                                    <option th:value="${areas.areaid}" th:text="${areas.area}"></option>
                                </span>
                            </select>
                        </div>
                        <div class="form-group form-inline">
                            <label for="detailedAddress">详细地址</label>
                            <input type="text" name="detailedAddress" class="form-control" id="detailedAddress" placeholder="请输入医院详细地址">
                        </div>
                        <div class="form-group form-inline">
                            <label for="starttime">开始时间</label>
                            <input type="text" name="starttime" class="layui-input" id="starttime" placeholder="yyyy-MM-dd HH:mm:ss">
                        </div>
                        <div class="form-group form-inline">
                            <label for="endtime">结束时间</label>
                            <input type="text" name="endtime"  class="layui-input" id="endtime"  placeholder="yyyy-MM-dd HH:mm:ss">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-warning" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-success" data-dismiss="modal" onclick="addDetectionPoint()">保存</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <table class="table table-bordered table-striped table-hover" style="margin-top: 10px">
        <input type="hidden" name="pageNo" id="pageNo" th:value="${pageInfo.pageNum}" >
        <input type="hidden" name="pageSize" id="pageSize" th:value="${pageInfo.pageSize}">
        <input type="hidden" id="pageTotal" th:value="${pageInfo.total}">
        <thead>
            <tr class="info">
                <th>接种点编号</th>
                <th>详细地址</th>
                <th>医院名称</th>
                <th>开始时间</th>
                <th>结束时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
        <tr th:each="detectionPoint:${detectionPointList}">
            <td th:text="${detectionPoint.detectionid}"></td>
            <td th:text="${detectionPoint.detailedAddress}"></td>
            <td th:text="${detectionPoint.name}"></td>
            <td th:text="${#dates.format(detectionPoint.starttime, 'yyyy-MM-dd HH:mm:ss')}"></td>
            <td th:text="${#dates.format(detectionPoint.endtime, 'yyyy-MM-dd HH:mm:ss')}"></td>
            <td>
                <button type="button" class="btn btn-warning btn-sm" data-toggle="modal" th:onclick="updateDPoint('[[${detectionPoint}]]')" data-target="#myUpdate">
                    <span class="glyphicon glyphicon-cog">修改</span></button>
                <button type="button" class="btn btn-danger btn-sm" th:onclick="'deleteDPoint('+${detectionPoint.detectionid}+')'">
                    <span class="glyphicon glyphicon-trash">删除</span></button>
            </td>
        </tr>
        </tbody>
    </table>
    <div id="pageDemo"></div>
    <div class="modal fade" id="myUpdate" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel2">修改检测点信息</h4>
                </div>
                <form id="myUpdataDPoint">
                    <div class="modal-body">
                        <input type="hidden" name="detectionid" id="detectionidU">
                        <div class="form-group form-inline">
                            <label>医院名称</label>
                            <input type="text" id="nameU" name="name" class="form-control" placeholder="请输入医院名称">
                        </div>
                        <input type="hidden" name="areaid" id="areaid">
                        <div class="form-group form-inline">
                            <label for="detailedAddress">详细地址</label>
                            <input type="text" id="detailedAddressU" name="detailedAddress" class="form-control" placeholder="请输入医院详细地址">
                        </div>
                        <div class="form-group form-inline">
                            <label>开始时间</label>
                            <input type="text" id="startTimeU" name="starttime" class="layui-input" pattern="yyyy-MM-dd HH:mm:ss" placeholder="yyyy-MM-dd HH:mm:ss">
                        </div>
                        <div class="form-group form-inline">
                            <label>结束时间</label>
                            <input type="text" id="endTimeU" name="endtime" class="layui-input" pattern="yyyy-MM-dd HH:mm:ss" placeholder="yyyy-MM-dd HH:mm:ss">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-warning" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-success" data-dismiss="modal" onclick="updateDPoint2()">保存修改</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="js/areaSelect.js"></script>
<script type="text/javascript" src="js/layuiDateForMate.js"></script>
<script type="text/javascript">
    function timeOutReflush() {
        setTimeout(function () {
            window.location.href='findAlldetectionPoint?pageNo='+$('#pageNo').val()+'&pageSize='+$('#pageSize').val();
        },1500);
    }
    function addDetectionPoint() {
        $.ajax({
            url: '/addDetectionPoint',
            type: 'post',
            data: $("#addForm").serialize(),
            success: function (result) {
                if(result=='SUCCESS'){   //登录成功
                    layer.msg("检测点添加成功",{icon:1});
                    timeOutReflush();
                }else{   //登录失败
                    layer.alert('检测点添加失败!',{icon:2});
                }
            }
        });
        return false;
    }
    function updateDPoint(detectionPoint) {   //弹出修改框并插入数据
        console.log(detectionPoint);
        var detectionPoint=eval("("+detectionPoint+")");   //将json转化成对象
        console.log(typeof detectionPoint);
        $("#detectionidU").val(detectionPoint.detectionid);
        $("#nameU").val(detectionPoint.name);
        $("#detailedAddressU").val(detectionPoint.detailedAddress);
        $("#startTimeU").val(translaDate(detectionPoint.starttime));
        $("#endTimeU").val(translaDate(detectionPoint.endtime));
        $("#areaid").val(detectionPoint.areaid);
    }
    function updateDPoint2() {
        $.ajax({
            url: '/updateDPoint',
            type: 'post',
            data: $("#myUpdataDPoint").serialize(),
            success: function (result) {
                console.log(result);
                if(result=='SUCCESS'){   //修改成功
                    layer.msg("监测点修改成功",{icon:1});
                    timeOutReflush();
                }else{   //登录失败
                    layer.alert('监测点修改失败!',{icon:2});
                }
            }
        });
        return false;
    }
    function deleteDPoint(detectionid) {
        layer.confirm('删除后数据将不可恢复，确认删除?', {
            btn: ['确认',  '取消'] //可以无限个按钮
            ,btn3: function(index, layero){
                layer.close(index);
            }
        }, function(index, layero){
            //按钮【按钮一】的回调
            $.ajax({
                url: '/deleteDPointById',
                type: 'post',
                data: {'detectionid':detectionid},
                success: function (result) {
                    if(result=='SUSSES'){   //登录成功
                        layer.alert("删除成功",{icon:1});
                        timeOutReflush();
                    }else{   //登录失败
                        layer.alert('删除失败!',{icon:2});
                    }
                }
            });
            layer.close(index);
        });
        return false;
    }
</script>
<script type="text/javascript">
    layui.use(['laypage', 'layer'], function(){
        var laypage = layui.laypage
            ,layer = layui.layer;
        var form = layui.form;
        var layer = layui.layer;
        var util = layui.util;

        let pageNo=parseInt($('#pageNo').val());
        let pageSize=parseInt($('#pageSize').val());
        let pageTotal=parseInt($('#pageTotal').val());

        //完整功能
        laypage.render({
            elem: 'pageDemo'
            ,count: pageTotal
            ,curr: pageNo
            ,limit: pageSize
            ,limits: [5,10,20,30,50]
            ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
            ,jump: function(obj,first){
                console.log(obj);
                if(!first){
                    //do something
                    /*$('#pageNo').val(obj.curr);
                    $('#pageSize').val(obj.limit);
                    $('#searchForm').submit();*/
                    console.log("pageNo="+obj.curr+",pageSize="+obj.limit);
                    location.href="findAlldetectionPoint?pageNo="+obj.curr+"&pageSize="+obj.limit;
                }
            }
        });
    });
</script>
</body>
</html>